 
#include "linklist.h"
#define N 20
int main()
{
	LinkNode *L;
    printf("请输入要建立的链表的长度:\n");
    int length = 0;
    scanf("%d",&length);
    
	int i,a[length];
	for (i=0;i<length;i++)
    {
        scanf("%d",&a[i]);
    }
   
    CreateListR(L,a,length);
    printf("创建的链表是：\n");
    LinkNode *r=L->next;
    for(int i=0;i<length;i++){
        if(i == length-1){
            printf("%d",r->data);
            break;
        }
        printf("%d->",r->data);
		r=r->next;
    }
    
    printf("\n");
    printf("删除后的结果是：\n");
    
    LNode *p = L;     
    while (p->next != nullptr) {
        LNode *q = p->next;
        while (q != nullptr) {
            if (q->next != nullptr && q->next->data == p->next->data) {
                LNode *toDelete = q->next;
                q->next = q->next->next;
                delete toDelete;
            } else {
                q = q->next;
            }
        }
        p = p->next;
    }

    // DispList(L);
    int length2 = ListLength(L);
    LinkNode *k=L->next;
    for(int i=0;i<length2;i++){
        if(i == length2-1){
            printf("%d",k->data);
            break;
        }
        printf("%d->",k->data);
		k=k->next;
    }

}
